package com.qf.dao;

import com.qf.pojo.Developer;
import com.qf.pojo.Item;
import com.qf.pojo.Subitem;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface SubitemDao {
    @Select("select  * from subitem  where pid=#{pid}")//单表查询
    @Results(id="projectMap",value={
            @Result(column = "suid",property = "suid"),
            @Result(column = "sname",property = "sname"),
            @Result(column = "starttime",property = "starttime"),
            @Result(column = "endtime",property = "endtime"),
            @Result(column = "pid",property = "pid"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "suid",property = "items",
                    many=@Many(select="com.qf.dao.ItemDao.findItemBySuid",fetchType = FetchType.EAGER))
    })

    List<Subitem> findSubitems();

    @Insert("<script>insert into subitem(\n" +
            "    <trim suffixOverrides=\",\">\n" +
            "        <if test=\"suid != null and suid != ''\">\n" +
            "            suid,\n" +
            "        </if>\n" +
            "        <if test=\"sname != null and sname != ''\">\n" +
            "            sname,\n" +
            "        </if>\n" +
            "       <if test=\"starttime!=null\">\n" +
            "                    starttime,\n" +
            "                </if>\n" +
            "                <if test=\"endtime!=null\">\n" +
            "                    endtime,\n" +
            "                </if>\n" +
            "        <if test=\"pid != null and pid != ''\">\n" +
            "            pid,\n" +
            "        </if>\n" +
            "       <if test=\"updatetime!=null\">\n" +
            "                    updatetime,\n" +
            "        </if>\n" +
            "    </trim>\n" +
            "    )\n" +
            "    values(\n" +
            "    <trim suffixOverrides=\",\">\n" +
            "        <if test=\"suid != null and suid != ''\">\n" +
            "            #{suid},\n" +
            "        </if>\n" +
            "        <if test=\"sname != null and sname != ''\">\n" +
            "            #{sname},\n" +
            "        </if>\n" +
            "         <if test=\"starttime!=null\">\n" +
            "                    #{starttime},\n" +
            "                </if>\n" +
            "                <if test=\"endtime!=null\">\n" +
            "                    #{endtime},\n" +
            "        </if>\n" +
            "        <if test=\"pid != null and pid != ''\">\n" +
            "            #{pid},\n" +
            "        </if>\n" +
            "        <if test=\"updatetime!=null\">\n" +
            "                    #{updatetime},\n" +
            "                </if>\n" +
            "    </trim>\n" +
            "    )</script>")
    public int addSubitem(Subitem subitem);
}
